package com.ccjq.shosestore.order.service.impl;

import com.ccjq.shosestore.order.bo.orderBo;
import com.ccjq.shosestore.order.bo.orderBoGl;
import com.ccjq.shosestore.order.dao.impl.orderDaoImpl;
import com.ccjq.shosestore.order.dao.orderDao;
import com.ccjq.shosestore.order.service.orderService;
import com.ccjq.shosestore.shoppingcart.bo.ShopcartBo;
import com.ccjq.shosestore.shoppingcart.service.Impl.ShopcartImpl;
import com.ccjq.shosestore.shoppingcart.service.Shopcart;

import java.util.ArrayList;
import java.util.List;

public class orederImpl implements orderService {

    private Shopcart sh = new ShopcartImpl();

    private orderDao or;

    public orederImpl() {
        or = new orderDaoImpl();
    }

    public boolean insertOrderXinXi(orderBo order) {
        return or.insertOrderXinXi(order);
    }

    public boolean insertOrderGL(orderBo order) {
        String order_rid= order.getOrder_id();
        String userid=order.getUser_id();
        List<ShopcartBo> list=sh.selectCar(userid);
        for(ShopcartBo bo:list)
        {
                 String prid=bo.getProduct_id();
               /* int price=or.Selectprice(prid);*/
                int price=bo.getPrice();
                int quantity=bo.getQuantity();
                or.insertOrderGL(order_rid,prid,quantity,price);
        }
        return true;
    }

    public boolean updateStock(String prid, int quantity) {
        return false;
    }

    public void deleteShopCar(String userid) {
      or.deleteShopCar(userid);
    }

    public orderBo selectXinXi(String id) {
        return null;
    }

    public boolean selectquntity(String prid, int newQuntity) {
        return or.selectquntity(prid,newQuntity);
    }

    public int UpdateStock(orderBo order) {
        String userid=order.getUser_id();
        List<ShopcartBo> list=sh.selectCar(userid);
        for(ShopcartBo bo:list)
        {
            String prid=bo.getProduct_id();
            /* int price=or.Selectprice(prid);*/
            int quantity=bo.getQuantity();
            or.UpdateStock(prid,quantity);
        }
        return 1;
    }

    public List<orderBo> selectAll(int startRow, int pageSize) {

        return or.selectAll(startRow,pageSize);
    }

    public int zhs(String userid) {
        return or.zhs(userid);
    }

    public orderBo dingdanXinXi(String orid) {
        return or.dingdanXinXi(orid);
    }

    public List<orderBoGl> shangpin(String orid) {

        List<orderBoGl> zj=or.shangpin(orid);
        List<orderBoGl> list=new ArrayList<orderBoGl>();
        for (orderBoGl ob:zj)
        {
            orderBoGl oob=new orderBoGl();
            oob.setProductid(ob.getProductid());
            oob.setQuantity(ob.getQuantity());
            oob.setDescription(ob.getDescription());
            oob.setPrice(ob.getPrice());
            oob.setXiaoji(ob.getPrice()*ob.getQuantity());
            list.add(oob);
        }
        return list;
    }


}
